package com.yqb.study;

import static com.google.common.base.Predicates.or;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.google.common.base.Predicate;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * jar包 启动入口
 */
@SpringBootApplication
@EnableScheduling
public class SpringbootstudyApplication extends WebMvcConfigurerAdapter{

	// 查看application.yml是否开启swagger
    @Value("${springbootstudy.swagger-open}")  
    private Boolean swaggerOpen;	
	
	public static void main(String[] args) {
		SpringApplication.run(SpringbootstudyApplication.class, args);
	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// http://ip:port/context-path/static/xx/xx指的都是访问静态资源
		// 截取xx/xx到static目录下寻找文件
		registry.addResourceHandler("/static/**").addResourceLocations("/static/");
		
		if (swaggerOpen) {
			// swagger-ui.html 是在springfox-swagger-ui.jar里的,需要指出,不然访问不到
			registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
			registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");			
		}
	}
}
